package com.xmb.wechat.contact;

import com.blankj.utilcode.util.Utils;
import com.xmb.wechat.R;
import com.xmb.wechat.bean.BankCardBean;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.common.Constant;

import java.util.List;

import io.objectbox.Box;
import io.objectbox.BoxStore;

public class InitContact {

    public static String[] banks         = new String[]{
            "中国银行", "农业银行", "工商银行",
            "建设银行", "交通银行", "民生银行",
            "招商银行", "邮政储蓄", "浦发银行",
            "兴业银行", "广发银行", "华夏银行",
            "光大银行", "中信银行", "恒丰银行",
            "农村信用社"};
    public static String[] fullBankNames = new String[]{
            "中国银行", "中国农业银行", "中国工商银行",
            "中国建设银行", "中国交通银行", "中国民生银行",
            "招商银行", "中国邮政储蓄", "上海浦东发展银行",
            "兴业银行", "广发银行", "华夏银行",
            "中国光大银行", "中信银行", "恒丰银行",
            "农村信用合作社"};

    public static String[] bankIcons = new String[]{
            "zg_bank.png", "ny_bank.png", "gs_bank.png",
            "js_bank.png", "jt_bank.png", "ms_bank.png",
            "zs_bank.png", "yzcx_bank.png", "pf_bank.png",
            "xy_bank.png", "gf_bank.png", "hx_bank.png",
            "gd_bank.png", "zx_bank.png", "hf_bank.png",
            "ncxys_bank.png"};

    /**
     * 初始化数据库
     */
    public static void initDB(BoxStore boxStore) {
        Box<WechatContactBean> box = boxStore.boxFor(WechatContactBean.class);
        List<WechatContactBean> list = box.query().build()
                .find();
        if (list.size() == 0) {
            WechatContactBean innerBean1 = new WechatContactBean();
            innerBean1.setName("新的朋友");
            innerBean1.setPingyin("↑");
            innerBean1.setFirstLetter("↑");
            innerBean1.setAvatar("" + R.drawable.ic_wx_contacts_new_friend);
            innerBean1.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_DRAWABLE);
            innerBean1.setInner(true);
            box.put(innerBean1);

            WechatContactBean innerBean2 = new WechatContactBean();
            innerBean2.setName("群聊");
            innerBean2.setPingyin("↑");
            innerBean2.setFirstLetter("↑");
            innerBean2.setAvatar("" + R.drawable.ic_wx_contacts_group_friend1380);
            innerBean2.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_DRAWABLE);
            innerBean2.setInner(true);
            box.put(innerBean2);

            WechatContactBean innerBean3 = new WechatContactBean();
            innerBean3.setName("标签");
            innerBean3.setPingyin("↑");
            innerBean3.setFirstLetter("↑");
            innerBean3.setAvatar("" + R.drawable.ic_wx_contact_tag);
            innerBean3.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_DRAWABLE);
            innerBean3.setInner(true);
            box.put(innerBean3);

            WechatContactBean innerBean4 = new WechatContactBean();
            innerBean4.setName("公众号");
            innerBean4.setPingyin("↑");
            innerBean4.setFirstLetter("↑");
            innerBean4.setAvatar("" + R.drawable.ic_wx_contacts_gzh);
            innerBean4.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_DRAWABLE);
            innerBean4.setInner(true);
            box.put(innerBean4);

            String[] names = Utils.getApp().getResources().getStringArray(R.array.wechat_inner_names);
            for (int i = 0; i < names.length; i++) {
                WechatContactBean vo = new WechatContactBean();
                vo.setName(names[i]);
                vo.setAvatar("avatar_" + i + ".jpg");
                vo.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_ASSETS);
                vo.setMute(false);
                innerBean4.setInner(false);
                box.put(vo);
            }
        }

    }

    /**
     * 去掉前四个
     *
     * @param boxStore
     */
    public static void initDB_New(BoxStore boxStore) {
        //添加联系人
        Box<WechatContactBean> box = boxStore.boxFor(WechatContactBean.class);
        List<WechatContactBean> list = box.query().build().find();
        if (list.size() == 0) {
            String[] names = Utils.getApp().getResources().getStringArray(R.array.wechat_inner_names);
            for (int i = 0; i < names.length; i++) {
                WechatContactBean vo = new WechatContactBean();
                vo.setName(names[i]);
                vo.setAvatar("avatar_" + (i + 1) + ".jpg");
                vo.setAvatarSrc(Constant.SourceType.AVATAR_SRC_APP_INNER_ASSETS);
                vo.setMute(false);
                box.put(vo);
            }
        }
        //添加银行卡
        Box<BankCardBean> bankCardBeanBox = boxStore.boxFor(BankCardBean.class);
        List<BankCardBean> bankCardList = bankCardBeanBox.query().build().find();
        if (bankCardList.size() == 0) {
            String[] strings = new String[]{"1358", "2588", "3786", "8988", "1228", "2338"};
            for (int i = 0; i < 6; i++) {
                BankCardBean bankCardBean = new BankCardBean();
                bankCardBean.setAvatar("file:///android_asset/banks/" + bankIcons[i]);
                bankCardBean.setBankName(banks[i]);
                bankCardBean.setBankNumber(strings[i]);
                bankCardBean.setFullBankName(fullBankNames[i]);
                bankCardBeanBox.put(bankCardBean);
            }
        }
    }

}
